package com.fourth.controller.api;

import com.fourth.dao.SortDao;
import com.fourth.service.BrandService;
import com.fourth.vo.BrandVo;
import com.ljx.entity.Brand;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Sort;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;

/**
 * @author xiaoZhu
 * @version 1.0
 * @date 2023/2/27 22:43
 */
@Api(value = "commodity/api/brand", tags = {""})
@RestController
@RequestMapping("commodity/api/brand")
public class ApiBrandController {

    @Autowired
    private BrandService brandService;

    @Autowired
    private SortDao sortDao;
    /**
     * 查询全部品牌
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "查询全部品牌", notes = "查询全部品牌", httpMethod = "POST")
    @PostMapping("/select")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody BrandVo brandVo

    ){
        return brandService.selectAll(currentPage,pageSize,brandVo);
    }

    @GetMapping("sort/select")
        public List<Sort> sorts(){
        List<Sort> list = sortDao.selectList(null);
        return list;
    }
    /**
     * 审核操作
     * @param brand
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Brand", name = "brand", value = "", required = true)
    })
    @ApiOperation(value = "审核操作", notes = "审核操作", httpMethod = "POST")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody Brand brand){
        System.out.println("brand = " + brand);
        boolean b = brandService.updateById(brand);
        if (b==true){
            return new Result(200,"审核完成");
        }
        return new Result(500,"审核失败");
    }

    /**
     * 根据id删除品牌
     * @param Id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "Id", value = "", required = true)
    })
    @ApiOperation(value = "删除品牌", notes = "", httpMethod = "POST")
    @PostMapping("/delece")
    public Result delece(Integer Id){
        boolean b = brandService.removeById(Id);
        if (b==true){
            return new Result(200,"删除成功");
        }
        return new Result(500,"删除失败");
    }
}
